/*
 * Copyright (c) GBA-NCTI-ISDC. 2022-2024.
 *
 * openGauss embedded is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 * http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITFOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 * -------------------------------------------------------------------------
 *
 * scan_plan.cpp
 *
 * IDENTIFICATION
 * openGauss-embedded/src/compute/sql/planner/logical_plan/scan_plan.cpp
 *
 * -------------------------------------------------------------------------
 */
#include "planner/logical_plan/scan_plan.h"

const Schema& ScanPlan::GetSchema() const {
    if (!IsOnlyCount()) {
        const auto& schema = source->GetSchema();
        if (projection_.empty()) {
            return schema;
        }
        schema_ = schema.Select(projection_);
    } else {
        std::vector<SchemaColumnInfo> columns;
        SchemaColumnInfo col_info;
        col_info.col_name = {"count_star"};
        col_info.col_type = LogicalType::Bigint();
        col_info.slot = 0;
        columns.push_back(col_info);
        schema_ = Schema(std::move(columns));
    }
    return schema_;
}
